package com.cbn.ibcp.web.jishiting.operator.convert;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.cbn.ibcp.common.utils.bean.BeanUtils;
import com.cbn.ibcp.jishiting.media.bo.EpisodeResourceStreamBO;
import com.cbn.ibcp.jishiting.media.domain.EpisodeResourceStream;
import com.cbn.ibcp.jishiting.rms.bo.ResourceStreamBO;
import com.cbn.ibcp.jishiting.rms.domain.ResourceStream;
import com.cbn.ibcp.web.jishiting.operator.dto.EpisodeResourceStreamDTO;
import com.cbn.ibcp.web.jishiting.operator.dto.ResourceStreamDTO;

import java.util.stream.Collectors;

public class ResourceStreamDTOConvert {

    public static ResourceStreamBO convertTOResourceStreamBO(ResourceStreamDTO resourceStreamDTO) {
        if (resourceStreamDTO == null) {
            return null;
        }
        ResourceStreamBO resourceStreamBO = new ResourceStreamBO();
        BeanUtils.copyBeanProp(resourceStreamBO, resourceStreamDTO);
        if (StrUtil.isNotBlank(resourceStreamDTO.getEpisodeId())) {
            resourceStreamBO.setEpisodeId(Long.parseLong(resourceStreamDTO.getEpisodeId()));
        }
        if (StrUtil.isNotBlank(resourceStreamDTO.getAlbumId())) {
            resourceStreamBO.setAlbumId(Long.parseLong(resourceStreamDTO.getAlbumId()));
        }
        if (CollUtil.isNotEmpty(resourceStreamDTO.getEpisodeIds())) {
            resourceStreamBO.setEpisodeIds(resourceStreamDTO.getEpisodeIds().stream().map(Long::parseLong).collect(Collectors.toList()));
        }
        if (CollUtil.isNotEmpty(resourceStreamDTO.getAlbumIds())) {
            resourceStreamBO.setAlbumIds(resourceStreamDTO.getAlbumIds().stream().map(Long::parseLong).collect(Collectors.toList()));
        }
        return resourceStreamBO;
    }
}
